/*
 * @Description: 
 * @Author: zyj
 * @Date: 2022-05-27 17:14:26
 * @LastEditors: zyj
 * @LastEditTime: 2022-05-27 17:14:44
 */
/* 实现new */
function mockNew(constructor, ...args) {
  //最好不要这么些，因为Object.create会有不兼容的情况，那么自己实现一个create方法内部是使用了new的，所以不要这么实现
  // let obj = Object.create(constructor.prototype);  
  let obj = {};
  obj.__proto__ = constructor.prototype;
  constructor.call(obj, ...args);
  return obj;
}


function Animal(name) {
  this.name = name;
  this.eat = function () {
    console.log(`${this.name}要吃饭啦`)
  }
}


let duck = mockNew(Animal, "鸭子");
duck.eat();